package com.my.framework.page;

import java.util.List;
public class Page
{
    
    /** The Constant ORDER_DIRECTION_ASC. */
    public final static String ORDER_DIRECTION_ASC = "ASC";
    
    /** The Constant ORDER_DIRECTION_DESC. */
    public final static String ORDER_DIRECTION_DESC = "DESC";
    
    /** 默认每页记录数. */
    public static final int DEFAULT_PAGE_SIZE = 20;
    
    /** 原始页码. */
    private int plainPageNum = 1;
    
    /** 当前页码. */
    protected int pageNum = 1;
    
    /** 每页记录数. */
    protected int numPerPage = DEFAULT_PAGE_SIZE;
    
    // 默认按照id倒序排列
    /** The order field. */
    private String orderField = "";
    
    /** The order direction. */
    private String orderDirection = "";
    
    /** 总页数. */
    private int totalPage = 1;
    
    /** 前一页. */
    private int prePage = 1;
    
    /** 下一页. */
    private int nextPage = 1;
    
    /** 总记录数. */
    protected long totalCount = 0;
    
    /** The user objects. */
    private List<?> userObjects;
    
    private List<PageOrder> orders=null;
    
    /**
     * 返回 pageNum 的值.
     *
     * @return pageNum
     */
    public int getPageNum()
    {
        if (pageNum > totalPage)
        {
            pageNum = totalPage;
        }
        return pageNum;
    }
    
    /**
     * 设置 当前页码 的值.
     *
     * @param pageNum the new 当前页码
     */
    public void setPageNum(int pageNum)
    {
        this.pageNum = pageNum > 0 ? pageNum : 1;
        this.plainPageNum = this.pageNum;
    }
    
    /**
     * 返回 numPerPage 的值.
     *
     * @return numPerPage
     */
    public int getNumPerPage()
    {
        return numPerPage;
    }
    
    /**
     * 设置 numPerPage 的值.
     *
     * @param numPerPage the new 每页记录数
     */
    public void setNumPerPage(int numPerPage)
    {
        this.numPerPage = numPerPage > 0 ? numPerPage : 10;
    }
    
    /**
     * 返回 orderField 的值.
     *
     * @return orderField
     */
    public String getOrderField()
    {
        return orderField;
    }
    
    /**
     * 设置 orderField 的值.
     *
     * @param orderField the new order field
     */
    public void setOrderField(String orderField)
    {
        this.orderField = orderField;
    }
    
    /**
     * 返回 orderDirection 的值.
     *
     * @return orderDirection
     */
    public String getOrderDirection()
    {
        return orderDirection;
    }
    
    /**
     * 设置 orderDirection 的值.
     *
     * @param orderDirection the new order direction
     */
    public void setOrderDirection(String orderDirection)
    {
        this.orderDirection = orderDirection;
    }
    
    /**
     * 返回 totalPage 的值.
     *
     * @return totalPage
     */
    public int getTotalPage()
    {
        return totalPage;
    }
    
    /**
     * 设置 totalPage 的值.
     *
     * @param totalPage the new 总页数
     */
    public void setTotalPage(int totalPage)
    {
        this.totalPage = totalPage;
    }
    
    /**
     * 返回 prePage 的值.
     *
     * @return prePage
     */
    public int getPrePage()
    {
        prePage = pageNum - 1;
        if (prePage < 1)
        {
            prePage = 1;
        }
        return prePage;
    }
    
    /**
     * 设置 prePage 的值.
     *
     * @param prePage the new 前一页
     */
    public void setPrePage(int prePage)
    {
        this.prePage = prePage;
    }
    
    /**
     * 返回 nextPage 的值.
     *
     * @return nextPage
     */
    public int getNextPage()
    {
        nextPage = pageNum + 1;
        if (nextPage > totalPage)
        {
            nextPage = totalPage;
        }
        
        return nextPage;
    }
    
    /**
     * 设置 nextPage 的值.
     *
     * @param nextPage the new 下一页
     */
    public void setNextPage(int nextPage)
    {
        this.nextPage = nextPage;
    }
    
    /**
     * 返回 totalCount 的值.
     *
     * @return totalCount
     */
    public long getTotalCount()
    {
        return totalCount;
    }
    
    /**
     * 设置 totalCount 的值.
     *
     * @param totalCount the new 总记录数
     */
    public void setTotalCount(long totalCount)
    {
        this.totalCount = totalCount;
        totalPage = (int)(totalCount - 1) / this.numPerPage + 1;
    }
    
    /**
     * 返回 plainPageNum 的值.
     *
     * @return plainPageNum
     */
    public int getPlainPageNum()
    {
        return plainPageNum;
    }
    
    /**
     * 设置 plainPageNum 的值.
     *
     * @param plainPageNum the new 原始页码
     */
    public void setPlainPageNum(int plainPageNum)
    {
        this.plainPageNum = plainPageNum;
    }
    
    /**
     * Gets the user objects.
     *
     * @return the user objects
     */
    public List<?> getUserObjects()
    {
        return userObjects;
    }
    
    /**
     * Sets the user objects.
     *
     * @param userObjects the new user objects
     */
    public void setUserObjects(List<?> userObjects)
    {
        this.userObjects = userObjects;
    }

	public List<PageOrder> getOrders() {
		return orders;
	}

	public void setOrders(List<PageOrder> orders) {
		this.orders = orders;
	}
    
}
